import matplotlib.pyplot as plt
import numpy as np

    
def plotres(file_name):
    x_data = ['MID','EDF','INS','SRPT','FB','THR','OPTFB','RM','SEDF','SALL']
    ind = np.arange(len(x_data))
    y_data1 = [352.66, 27.08, 7.16, 294.48, 13.1, 12.74, 10.56, 468.78, 10.96, 340.04]
    y_data2 = [374, 68, 15, 340, 30, 30, 22, 511, 20, 482]
    w = 0.2
    ax = plt.subplot(111)
    a = ax.bar(ind,y_data1,width=0.2,align='center')
    b = ax.bar(ind+w,y_data2,width=0.2,align='center')
    ax.set_xticks(ind+w)
    ax.set_xticklabels( ('MID','EDF','INS','SRPT','FB','THR','OPTFB','RM','SEDF','SALL') )
    plt.legend((a,b),('ave miss','worst miss'))
    plt.autoscale(tight=True)
    plt.title('The average/worst number of jobs that missed their deadlines')
    plt.savefig(file_name+'miss_count.png')
    # plt.show()
    plt.close()

    #--------------------------------------------------------------------
    x_data = ['MID','EDF','INS','SRPT','FB','THR','OPTFB','RM','SEDF','SALL']
    y_data = [0.9323608590585009, 0.9948061714010654, 0.9986267254648048, 0.9435192827721525, 0.9974874540173674, 0.997556498896539, 0.997974616526878, 0.9100892933181965, 0.997897884536893, 0.9347814577857295]
    plt.bar(x_data,y_data)
    plt.title('The average completion rate')
    plt.savefig(file_name+'ave_cr.png')
    # plt.show()
    plt.close()a

if __name__ == '__main__':
    file_name = f'/Users/liuchangkundeimac/real-time-scheduling/8_0.9_0.9_experiment/test9/'
    plotres(file_name)
        
